package org.ourgrid.broker.communication.sender;

import org.ourgrid.broker.communication.dao.AccountingAggregatorDAO;
import org.ourgrid.broker.response.AddAccountingAggregatorResponseTO;
import org.ourgrid.common.interfaces.AccountingAggregator;
import org.ourgrid.common.internal.SenderIF;

import br.edu.ufcg.lsd.commune.container.servicemanager.ServiceManager;
import br.edu.ufcg.lsd.commune.identification.ServiceID;

public class AddAccountingAggregatorSender implements SenderIF<AddAccountingAggregatorResponseTO> {

	public void execute(AddAccountingAggregatorResponseTO response,
			ServiceManager manager) {
		ServiceID peerAccountingServiceID = ServiceID.parse(response.getPeerAccountingAddress());
		
		AccountingAggregator peerAccounting = (AccountingAggregator) manager.getStub(peerAccountingServiceID, AccountingAggregator.class);

		AccountingAggregatorDAO.getInstance().addAccountingAggregator(ServiceID.parse(response.getPeerAddress()), peerAccounting);
	}

}
